
package com.monlyu.tag.extend;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;
import com.monlyu.tag.BaseTag;
import com.monlyu.util.BeanUtil;
import com.monlyu.util.FtlUtil;
import com.monlyu.util.StringUtil;
import com.monlyu.vo.Enums;

/*******************************************************************************
 * <b>功能描述☞</b>参数类型的下拉列表<br>
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>monlyu<br>
 * <b>文件路径☞</b>com.monlyu.tag.extend.SelectTag.java<br>
 * <b>开发日期☞</b>2010-1-30 <br>
 * 
 * @author monlyu
 * @since JDK 5
 * @version 1.0.8
 ******************************************************************************/
public class SelectTag extends BaseTag {

    private String name;

    private String cssClass;

    private String enumType;

    private Integer initval;

    private String headValue;

    private String headKey;

    public void setHeadValue(String headValue){
        this.headValue = headValue;
    }

    public void setHeadKey(String headKey){
        this.headKey = headKey;
    }

    public void setName(String name){
        this.name = name;
    }

    public void setCssClass(String cssClass){
        this.cssClass = cssClass;
    }

    public void setEnumType(String enumType){
        this.enumType = enumType;
    }

    public void setInitval(Integer initval){
        this.initval = initval;
    }

    /**
     * @author monlyu
     * @since 2009-12-27
     */
    @Override
    public int doStartTag(){
        Map<String, Object> data = Maps.newHashMap();
        data.put("cssClass", cssClass);
        data.put("name", name);
        if (!StringUtil.isEmpty(headKey)) {
            data.put("headKey", headKey);
        }
        if (headValue != null) {
            data.put("headValue", headValue);
        }
        List<Enums> list = BeanUtil.getValues(enumType);
        data.put("valueList", list);
        data.put("size", list.size());
        Object propValue = getValueFromValueStack(name);
        data.put("initval", initval == null ? (propValue == null ? 0 : propValue) : initval);
        try {
            write2Page(FtlUtil.render2Ftl(data, "select.ftl"));
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return SKIP_BODY;
    }
}
